local lor = require("lor.index")
local app = lor()

-- 模板配置
--app:conf("view enable", true)
--app:conf("view engine", "tmpl")
--app:conf("view ext", "html")
--app:conf("view layout", "")
--app:conf("views", "./app/views")

-- hello world
app:get("/index", function(req, res, next)
    res:send("hello world22222!")
end)

-- filter: add response header
app:use(function(req, res, next)
    res:set_header('X-Powered-By', 'Mango IWeb/1.0.0')
    next()
end)

-- 错误处理中间件
app:erroruse(function(err, req, res, next)
    ngx.log(ngx.ERR, err)
    ngx.log(ngx.ERR,"XXX")
    if req:is_found() ~= true then
        res:status(404):send("404! sorry, not found. ")
    else
        res:status(500):send("internal error")
    end
end)

return app